package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.FndDistrict;
import com.bestow.basic.service.IFndDistrictService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 区Controller
 * 
 * @author liliu
 * @date 2022-09-06
 */
@RestController
@RequestMapping("/basic/fndDistrict")
public class FndDistrictController extends BaseController
{
    @Autowired
    private IFndDistrictService fndDistrictService;

    /**
     * 查询区列表
     */
    @PreAuthorize("@ss.hasPermi('basic:fndDistrict:list')")
    @GetMapping("/list")
    public TableDataInfo list(FndDistrict fndDistrict)
    {
        startPage();
        List<FndDistrict> list = fndDistrictService.selectFndDistrictList(fndDistrict);
        return getDataTable(list);
    }

    /**
     * 导出区列表
     */
    @PreAuthorize("@ss.hasPermi('basic:fndDistrict:export')")
    @Log(title = "区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FndDistrict fndDistrict)
    {
        List<FndDistrict> list = fndDistrictService.selectFndDistrictList(fndDistrict);
        ExcelUtil<FndDistrict> util = new ExcelUtil<FndDistrict>(FndDistrict.class);
        util.exportExcel(response, list, "区数据");
    }

    /**
     * 获取区详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:fndDistrict:query')")
    @GetMapping(value = "/{district}")
    public AjaxResult getInfo(@PathVariable("district") String district)
    {
        return AjaxResult.success(fndDistrictService.selectFndDistrictByDistrict(district));
    }

    /**
     * 新增区
     */
    @PreAuthorize("@ss.hasPermi('basic:fndDistrict:add')")
    @Log(title = "区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FndDistrict fndDistrict)
    {
        return toAjax(fndDistrictService.insertFndDistrict(fndDistrict));
    }

    /**
     * 修改区
     */
    @PreAuthorize("@ss.hasPermi('basic:fndDistrict:edit')")
    @Log(title = "区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FndDistrict fndDistrict)
    {
        return toAjax(fndDistrictService.updateFndDistrict(fndDistrict));
    }

    /**
     * 删除区
     */
    @PreAuthorize("@ss.hasPermi('basic:fndDistrict:remove')")
    @Log(title = "区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{districts}")
    public AjaxResult remove(@PathVariable String[] districts)
    {
        return toAjax(fndDistrictService.deleteFndDistrictByDistricts(districts));
    }
}
